<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basepath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>公司单位管理</title>
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <link href="<%=basepath%>css/index.css" rel="stylesheet" type="text/css">
    <link href="<%=basepath%>css/company.css" rel="stylesheet" type="text/css">
    <script src="<%=basepath%>js/jquery-1.8.3.min.js"></script>
    <script src="<%=basepath%>js/layer/layer.js"></script>
</head>
<body>
<%
String code = request.getParameter("code");
String state =request.getParameter("state");
%>
<div class="viewport">
    <div class="header">
       <div class="header-1">
           <a href="javascrpt:void(0)" id="join" class="header-2">
              <span id="account" class="account">${empty user.realName ? '' : user.realName}</span>&nbsp;&nbsp;<span id="deptName" class="deptName">${user.departmentName}</span>
           </a>
           <a href="/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=company&prefix=3g_company&entrance=yes" class="back" id="back">返回</a>
           <span class="span-num main">WOP12000</span>
       </div>
    </div>
    <script type="text/javascript">$("#back").hide();</script>
    <div class="content m-top">
        <div class="content-1">
            <div class="blank-1"></div>
            <div class="content-1-1">
                <img alt="" src="<%=basepath%>images/b105.png" class="img-3" id="img-cpn">
                <table>
                    <tr>
                        <td class="td-1">姓名：</td>
                        <td class="td-2"><b id="nam">${user.realName}</b></td>
                    </tr>
                    <tr>
                        <td class="td-1">电话：</td>
                        <td class="td-2" id="phn">${user.atUserId}</td>
                    </tr>
                </table>
            </div>
            <div class="blank-1"></div>
            <div class="content-1-2">
                <span class="span-3"><b class="span-3-1"><span>公司名称：</span><span id="cpn">${empty user.companyName ? '您还未加入或创建公司' : user.companyName}</span></b></span>
            </div>
            <!-- <div class="content-1-2">
                <span class="span-3"><b><span>公司地址：</span><span id="cpn"></span></b></span>
            </div> -->
            <div class="blank"></div>
            <div class="blank"></div>
        </div>
        <div class="blank"></div>
        <div class="content-2">
            <a href="javascript:void(0)" class="content-2-1" id="detail">
                <img alt="" src="<%=basepath%>images/b101.png" class="img-1"><span class="span-1">公司详情</span><img src="<%=basepath%>images/b49.png" class="img-2">
            </a>
        </div>
        <div class="blank"></div>
        <div class="content-2">
            <a href="javascript:void(0)" class="content-2-1" id="depart">
                <img alt="" src="<%=basepath%>images/b102.png" class="img-1"><span class="span-1">部门岗位</span><img src="<%=basepath%>images/b49.png" class="img-2">
            </a>
        </div>
        <div class="blank"></div>
        <div class="content-2">
            <a href="javascript:void(0)" class="content-2-1" id="manage">
                <img alt="" src="<%=basepath%>images/b103.png" class="img-1"><span class="span-1">员工管理</span><img src="<%=basepath%>images/b49.png" class="img-2">
            </a>

        </div>
        <div class="blank"></div>
        <%-- <div class="content-2">
            <a href="javascript:void(0)" class="content-2-1" id="create">
                <img alt="" src="<%=basepath%>images/b104.png" class="img-1"><span class="span-1">创建公司</span><img src="<%=basepath%>images/b49.png" class="img-2">
            </a>
        </div>
        <div class="blank"></div> --%>
        <div class="content-2">
            <a href="javascript:void(0)" class="content-2-1" id="joinCmp">
                <img alt="" src="<%=basepath%>images/join.png" class="img-1"><span class="span-1">加入公司</span><img src="<%=basepath%>images/b49.png" class="img-2">
            </a>
        </div>
        <div class="blank"></div>
        <div class="content-2">
            <a href="javascript:void(0)" class="content-2-1" id="joinCom">
                <img alt="" src="<%=basepath%>images/huan.png" class="img-1"><span class="span-1">退出公司</span><img src="<%=basepath%>images/b49.png" class="img-2">
            </a>
        </div>
        <div class="blank"></div>
        <div class="space"></div>
    </div>
</div>
</body>
<script type="text/javascript">
    /*错误提示*/
    $(function(){
        var error = "${requestScope.returnMsg}";
        if(error != "" && error != "成功!"){
            layer.msg(error,{shadeClose:true,shade:0.1,time:2000});
        }
    });
    /*识别浏览器*/
    $(function(){
        var ua = window.navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i) == 'micromessenger'){
            /*微信公共号*/
            layer.load();
            $.ajax({
                url:"/wape-web/api/core/centerService",
                dataType:"json",
                data:{
                    serviceCode:"1001W01",
                    code:"<%=code %>"
                },
                complete:function(xhr,status){
                	var openId = xhr.responseText.replace(/(\n)+|(\r\n)+/g, "");
                    if(openId == "null" || openId == ""){
                        layer.closeAll();
                        window.location.href="/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=company&prefix=3g_company&entrance=yes";
                    }
                    else{
                        $.ajax({
                            type:"post",
                            url:"/wape-web/api/core/centerService",
                            data:{
                                serviceCode:"1001W02",
                                sign: 'web',
                                timestamp: 'web',
                                nonce: 'web',
                                editUser: 'web',
                                editTime: 'web',
                                device: 'web',
                                ipaddr: 'web',
                                mac: 'web',
                                openId:openId
                            },
                            success:function(data){
                                var wechat = eval("("+data+")");
                                if(wechat.returnCode == "200"){
                                    layer.closeAll();
                                    if(wechat.result.realName != ""){
                                        $("#account").text(wechat.result.realName);
                                    }
                                    else if(wechat.result.realName == ""){
                                        $("#account").text("您还未登录哦！");
                                    }
                                    $("#compNickName").text(wechat.result.companyNickName);
                                    $("#deptName").text(wechat.result.departmentName);
                                    if(wechat.result.realName != ""){
                                        $("#nam").text(wechat.result.realName);
                                    }
                                    if(wechat.result.atUserId != ""){
                                        $("#phn").text(wechat.result.atUserId);
                                    }
                                    if(wechat.result.companyName != undefined && wechat.result.companyName != ""){
                                        $("#cpn").text(wechat.result.companyName);
                                        $("#detail").attr("href","/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=details&prefix=3g_company&openId="+openId+ "&isWX=yes");
                                        $("#depart").attr("href","/wape-web/api/core/centerService?serviceCode=MMZS141&openId="+openId+ "&isWX=yes");
                                        $("#manage").attr("href","/wape-web/api/core/centerService?serviceCode=MMZS132&openId="+openId+ "&isWX=yes");
                                        /*创建公司*/
                                        $("#create").click(function(){
                                            layer.confirm('创建新公司必须先退出您现有公司，是否继续？',{
                                                icon: 3,
                                                title:'创建公司'
                                            },function(sure){
                                                layer.closeAll();
                                                layer.load();

                                                $.ajax({
                                                    type:"post",
                                                    url:"/wape-web/api/core/centerService",
                                                    data:{
                                                        serviceCode:"5006U08"
                                                    },
                                                    success:function(data){
                                                        //alert(data)
                                                        var sure = eval("("+data+")");
                                                        if(sure.returnCode == "200"){
                                                            layer.closeAll();
                                                            location.reload();
                                                        }
                                                        else{
                                                            layer.closeAll();
                                                            layer.msg("退出公司失败",{shadeClose:true,shade:0.1,time:2000});
                                                        }
                                                    }
                                                });

                                            });
                                        });
                                        $("#joinCmp").click(function(){
                                            layer.msg("您已加入公司,请退出公司",{shadeClose:true,shade:0.1,time:2000});
                                        });
                                        /*换公司*/
                                        $("#joinCom").click(function(){
                                            layer.confirm('您现在退出现有公司，是否继续？',{
                                                icon: 3,
                                                title:'退出公司'
                                            },function(sure){
                                                layer.closeAll();
                                                layer.load();

                                                $.ajax({
                                                    type:"post",
                                                    url:"/wape-web/api/core/centerService",
                                                    data:{
                                                        serviceCode:"5006U08"
                                                    },
                                                    success:function(data){
                                                        //alert(data)
                                                        var sure = eval("("+data+")");
                                                        if(sure.returnCode == "200"){
                                                            layer.closeAll();
                                                            location.reload();
                                                        }
                                                        else{
                                                            layer.closeAll();
                                                            layer.msg("退出公司失败",{shadeClose:true,shade:0.1,time:2000});
                                                        }
                                                    }
                                                });

                                            });
                                        });
                                    }
                                    else if(wechat.result.companyName == undefined || wechat.result.companyName == ""){
                                        $("#create").attr("href","/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=registered-3&prefix=3g&openId="+openId+ "&isWX=yes");
                                        $("#joinCmp").attr("href","/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=company-2&prefix=3g_company&openId="+openId+ "&isWX=yes");
                                        $("#detail").click(function(){
                                            layer.msg("请先加入公司",{shadeClose:true,shade:0.1,time:2000});
                                        });
                                        $("#depart").click(function(){
                                            layer.msg("请先加入公司",{shadeClose:true,shade:0.1,time:2000});
                                        });
                                        $("#manage").click(function(){
                                            layer.msg("请先加入公司",{shadeClose:true,shade:0.1,time:2000});
                                        });
                                        $("#joinCom").click(function(){
                                            layer.msg("您还未加入公司",{shadeClose:true,shade:0.1,time:2000});
                                        });
                                    }
                                    if(wechat.result.postalAddress != ""){
                                        $("#cpa").text(wechat.result.postalAddress);
                                    }
                                    if(wechat.result.realName != ""){
                                        $("#unm").text(wechat.result.realName);
                                    }
                                    if(wechat.result.atUserId != ""){
                                        $("#atu").text(wechat.result.atUserId);
                                    }
                                }
                                else{
                                    layer.closeAll();
                                    $("#account").text("您还未登录哦！");
                                    layer.msg("您未绑定农商号，请登录绑定！",{shadeClose:true,shade:0.1,time:2000});
                                }
                            }
                        })
                    }

                }
            });
        }
        else{
        	/*公司状态*/
            $(function(){
                var create = "${user.companyName}";
                if(create == ""){
                    $("#create").attr("href","/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=registered-3&prefix=3g");
                    $("#joinCmp").attr("href","/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=company-2&prefix=3g_company");
                    $("#detail").click(function(){
                        layer.msg("请先加入公司！",{shadeClose:true,shade:0.1,time:2000});
                    });
                    $("#depart").click(function(){
                        layer.msg("请先加入公司！",{shadeClose:true,shade:0.1,time:2000});
                    });
                    $("#manage").click(function(){
                        layer.msg("请先加入公司！",{shadeClose:true,shade:0.1,time:2000});
                    });
                    $("#joinCom").click(function(){
                        layer.msg("请先加入公司！",{shadeClose:true,shade:0.1,time:2000});
                    });
                    
                }
                else if(create != ""){
                    $("#detail").attr("href","/wape-web/api/core/centerService?serviceCode=WJ9999&targetURL=details&prefix=3g_company");
                    $("#depart").attr("href","/wape-web/api/core/centerService?serviceCode=MMZS141");
                    $("#manage").attr("href","/wape-web/api/core/centerService?serviceCode=MMZS132");
                    /*创建公司*/
                    $("#create").click(function(){
                        layer.confirm('创建新公司必须先退出您现有公司，是否继续？',{
                            icon: 3,
                            title:'创建公司'
                        },function(sure){
                            layer.closeAll();
                            layer.load();

                            $.ajax({
                                type:"post",
                                url:"/wape-web/api/core/centerService",
                                data:{
                                    serviceCode:"5006U08"
                                },
                                success:function(data){
                                    var sure = eval("("+data+")");
                                    if(sure.returnCode == "200"){
                                        layer.closeAll();
                                        location.reload();
                                    }
                                    else{
                                        layer.closeAll();
                                        layer.msg("退出公司失败",{shadeClose:true,shade:0.1,time:2000});
                                    }
                                }
                            });

                        });
                    });
                    $("#joinCmp").click(function(){
                        layer.msg("您已加入公司,请退出公司！",{shadeClose:true,shade:0.1,time:2000});
                    });
                    /*换公司*/
                    $("#joinCom").click(function(){
                        layer.confirm('您退出现有公司，是否继续？',{
                            icon: 3,
                            title:'退出公司'
                        },function(sure){
                            layer.closeAll();
                            $.ajax({
                                type:"post",
                                url:"/wape-web/api/core/centerService",
                                data:{
                                    serviceCode:"5006U08"
                                },
                                success:function(data){
                                    var sure = eval("("+data+")");
                                    if(sure.returnCode == "200"){
                                        layer.closeAll();
                                        location.reload();
                                    }
                                    else{
                                        layer.msg("退出公司失败",{shadeClose:true,shade:0.1,time:2000});
                                    }
                                }
                            });

                        });
                    });
                }
            });
        }
    });
</script>
</html>

